﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace Doctor.Data
{
    public class AccountManagementRepository
    {
        /// <summary>
        /// Checks whether the user credentials entered are valid or not.
        /// </summary>
        /// <param name="username">username to login</param>
        /// <param name="password">password to match</param>
        /// <returns></returns>
        public bool UserAuthenticated(string username, string password)
        {
            using (var ddc = new DoctorDataContext())
            {
                int totalUsersFound = (from users in ddc.tblUsers
                                       where
                                           users.UserName.Trim().ToLower().Equals(username.Trim().ToLower()) &&
                                           users.Password.Trim().ToLower().Equals(password.ToLower()) &&
                                           users.IsActive.Equals(true) &&
                                           users.IsDeleted.Equals(false)
                                       select users).Count();

                return totalUsersFound > 0 && totalUsersFound == 1;
            }
        }
    }
}
